<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button onclick="showDom()">获取页面2的DOM</button>
    <!-- 同源，能获取到DOM -->
    <!-- <iframe id="frame" src="./z.html" style="width: 100%;height: 300px;" frameborder="1"></iframe> -->

    <!-- 非同源，报错！！！ -->
    <!-- <iframe id="frame" src="https://www.bilibili.com/" style="width: 100%;height: 300px;" frameborder="1"></iframe> -->
    <script>
      function showDom() {
        const frame = document.getElementById("frame");
        console.log(frame.contentWindow.document);
      }
    </script>
  </body>
</html>
